import time

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import win32gui
import win32con

#This example requires Selenium WebDriver 3.13 or newer
# with webdriver.Chrome() as driver:
#     wait = WebDriverWait(driver, 10)
#     driver.get("https://wing.coupang.com/")
#     driver.find_element(By.ID, "userID").send_keys("hl20200123" + Keys.RETURN)
#     driver.find_element(By.ID, "userPWD").send_keys("herokenoty21144" + Keys.RETURN)
#     driver.find_element(By.ID, "btnLogin").click()
#     time.sleep(5)
#     first_result = wait.until(presence_of_element_located((By.CSS_SELECTOR, "vendor-auth-widget-button-send-sms")))
#     print(first_result.get_attribute("textContent"))
#     time.sleep(5)

# driver = webdriver.Chrome()
# driver.get('http://sahitest.com/demo/php/fileUpload.htm')
# upload = driver.find_element_by_id('file')
# upload.send_keys('e:\\test.txt')  # send_keys
# print(upload.get_attribute('value'))  # check value
#
# driver.quit()


dr = webdriver.Chrome()
dr.get('http://sahitest.com/demo/php/fileUpload.htm')
upload = dr.find_element(By.ID, "file")
# upload.click()
ActionChains(dr).move_to_element(upload).move_by_offset(5,5).click().perform()
time.sleep(5)

# win32gui
dialog = win32gui.FindWindow('#32770', u'打开')  # 对话框
ComboBoxEx32 = win32gui.FindWindowEx(dialog, 0, 'ComboBoxEx32', None)
ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)
Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)  # 上面三句依次寻找对象，直到找到输入框Edit对象的句柄
button = win32gui.FindWindowEx(dialog, 0, 'Button', None)  # 确定按钮Button

win32gui.SendMessage(Edit, win32con.WM_SETTEXT, None, 'e:\\test.txt')  # 往输入框输入绝对地址
win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button)  # 按button

print
upload.get_attribute('value')

time.sleep(10)
dr.quit()